/**
 * Copyright (c) 2011-11-8 WKM and/or its affiliates. 
 * Use is subject to license terms.
 * All rights reserved.
 */
package org.wkm.definition;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.jar.JarFile;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author WKM
 * Modification history
 * 1.WKM - 2011-11-8 -Create File
 */
public class ReaderJar {
	
	private static Logger logger = LoggerFactory.getLogger(ReaderJar.class);

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}
	
	/**
	 * 读取Jar包内的文件
	 * @param jarPath   例如：D:\jar\tool.jar
	 * @param fileName  例如：configFile/configXml.XML
	 *                Jar包内configFile目录下的configXml.XML文件
	 * @throws IOException 读取Jar包错误会抛出IO异常
	 */
	public void readJarFile(String jarPath,String fileName) throws IOException{
		JarFile file = new JarFile(jarPath);
		logger.info("read:" + file.getName());
		InputStream input = file.getInputStream(file.getJarEntry(fileName));
		InputStreamReader isr = new InputStreamReader(input);
		BufferedReader reader = new BufferedReader(isr);
		String strLine = null;
		while((strLine = reader.readLine()) != null){
			logger.info(strLine);
		}
		reader.close();
		isr.close();
		input.close();
	}

}
